package com.guan.poi.xml;


import com.guan.poi.xml.config.WorkbookConfig;
import com.guan.poi.exception.ExcelException;
import com.guan.poi.xml.util.XmlExcelUtil;

import java.util.Map;

/**
 * Excel 生成器
 */
public class PoiXmlManager {
	protected PoiXmlConfigManager configManager;

	public PoiXmlManager() {
		this.configManager = new PoiXmlConfigManager();
		FunctionManager.initClass("PoiUtil", XmlExcelUtil.class);
		FunctionManager.initClass("Long", Long.class);
		FunctionManager.initClass("Integer", Integer.class);
		FunctionManager.initClass("Float", Float.class);
		FunctionManager.initClass("String", String.class);
	}

	@Deprecated
	public WorkbookConfig loadFromPath(String locations) {
		return configManager.loadFromPath(locations);
	}

	public WorkbookConfig loadFromStr(String templateId, String xml) {
		return configManager.loadFromStr(templateId, xml);
	}

	@Deprecated
	public WorkbookConfig loadFromStr(String xml) {
		return configManager.loadFromStr(xml);
	}

	public PoiXmlBuilder createBuilder(String id, Map<String, Object> params) {
		WorkbookConfig config = configManager.getWorkbookConfig(id);
		if(config==null) {
			config = initWorkbookConfig(id);
		}
		initParams(config, params);
		return new PoiXmlBuilder(config, params);
	}

	public WorkbookConfig initWorkbookConfig(String id) {
		throw new ExcelException("模板"+id+"不存在");
	}

	public void initParams(WorkbookConfig config, Map<String, Object> params) {

	}
}
